import {
  Table,
  Model,
  Column,
  DataType,
  ForeignKey,
  BelongsTo,
  PrimaryKey,
  AutoIncrement,
  Unique,
} from 'sequelize-typescript';
import { RepairItem } from './repairItem.entity';
import {House} from "./house.entity"
import { User } from './user.entity';
@Table({
  comment: '报修表',
  tableName: 'repair',
})
export class Repair extends Model {
  @PrimaryKey
  @AutoIncrement
  @Unique
  @Column({
    type: DataType.BIGINT,
    allowNull: false,
    comment: '报修id',
  })
  id: number;

  @Column({
    type: DataType.STRING(200),
    allowNull: false,
    comment: '问题描述',
  })
  description: string;

  @Column({
    type: DataType.ENUM('0', '1', '2', '3'),
    allowNull: false,
    defaultValue: '1',
    comment: '1受理中2上门中0已取消3已完成',
  })
  status: number;

  @Column({
    type: DataType.DATE,
    allowNull: false,
    comment: '预约上门时间',
  })
  appointment: string;

  @Column({
    type: DataType.BIGINT('11'),
    allowNull: false,
    comment: '联系电话',
  })
  phone: number;

  @Column({
    type: DataType.JSON,
    allowNull: true,
    defaultValue: [],
    comment: '附件信息',
  })
  attachment: string[];

  @ForeignKey(() => RepairItem)
  @Column(DataType.BIGINT)
  repairItemId: number;

  @BelongsTo(() => RepairItem) // 指定这是一个属于（BelongsTo）关系
  repairItem: RepairItem;

  @ForeignKey(() => House)
  @Column(DataType.BIGINT)
  houseId: number;

  @BelongsTo(() => House) // 指定这是一个属于（BelongsTo）关系
  house: House;


  @ForeignKey(() => User)
  @Column(DataType.BIGINT)
  userId: number;

  @BelongsTo(() => User) // 指定这是一个属于（BelongsTo）关系
  user: User;
}
// Repair.sync({ alter: true })
